package com.czl.module_service.viewmodel

import com.czl.base.base.BaseBean
import com.czl.base.base.BaseViewModel
import com.czl.base.base.MyApplication
import com.czl.base.data.DataRepository
import com.czl.base.data.bean.tengyun.HealthReportBean
import com.czl.base.data.bean.tengyun.NoticeListBean
import com.czl.base.event.SingleLiveEvent
import com.czl.base.extension.ApiSubscriberHelper
import com.czl.base.util.RxThreadHelper

class HealthReportDetailViewModel(application: MyApplication, model: DataRepository) :
    BaseViewModel<DataRepository>(application, model) {

    val uc = UiChangeEvent()
    var bean: HealthReportBean.Data? = null

    class UiChangeEvent {
        val loadCompleteEvent: SingleLiveEvent<HealthReportBean.Data> = SingleLiveEvent()
    }

    fun setData(data: HealthReportBean.Data?) {
        data?.userName = model.getLoginName().toString()
        bean = data
    }

    fun selectHealthyAndRelativesById(announcementId: Int) {
        model.selectHealthyAndRelativesById(announcementId)
            .compose(RxThreadHelper.rxSchedulerHelper(this))
            .subscribe(object : ApiSubscriberHelper<BaseBean<HealthReportBean.Data>>(){
                override fun onResult(t: BaseBean<HealthReportBean.Data>) {
                    if (t.state == 0){
                        uc.loadCompleteEvent.postValue(t.data)
                    }else{
                        uc.loadCompleteEvent.postValue(null)
                    }
                }

                override fun onFailed(msg: String?) {
                    showErrorToast(msg)
                    uc.loadCompleteEvent.postValue(null)
                }
            })
    }
}